package com.hzhr.iot.huaweiiot.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.huaweiiot.controller.base.BaseController;
import com.hzhr.iot.huaweiiot.model.device.addDevice.AddDeviceModel;
import com.hzhr.iot.huaweiiot.model.device.addDevice.AddDeviceResponse;
import com.hzhr.iot.huaweiiot.model.device.deleteDevice.DeleteDeviceModel;
import com.hzhr.iot.huaweiiot.model.device.deleteDevice.DeleteDeviceResponse;
import com.hzhr.iot.huaweiiot.model.device.editDevice.EditDeviceModel;
import com.hzhr.iot.huaweiiot.model.device.editDevice.EditDeviceResponse;
import com.hzhr.iot.huaweiiot.service.DeviceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "device", description = "设备相关服务")
@RestController
@RequestMapping(value = "")
public class DeviceController extends BaseController {
    @Autowired
    DeviceService deviceService;

    //region /addDevice POST
    //region swagger响应码 : addDevice
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 在华为iot平台新增设备台账  \n----异常说明 : 华为iot平台服务调用错误  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : addDevice
    @ApiOperation(value="新增设备", notes="新增设备  \n范围 : 系统  \n步骤 :  \n1. 在华为iot平台新增设备台账; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : addDevice
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : addDevice
    @RequestMapping(value = "/addDevice", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<AddDeviceResponse> addDevice(@RequestParam @ApiIgnore Map<String, Object> query,
                                                               @RequestBody AddDeviceModel body) throws ServiceException {
        AddDeviceResponse responseBody = deviceService.addDevice(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /editDevice POST
    //region swagger响应码 : editDevice
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 在华为iot平台修改设备台账  \n----异常说明 : 华为iot平台服务调用错误  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : editDevice
    @ApiOperation(value="修改设备", notes="修改设备  \n范围 : 系统  \n步骤 :  \n1. 在华为iot平台修改设备台账; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : editDevice
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : editDevice
    @RequestMapping(value = "/editDevice", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<EditDeviceResponse> editDevice(@RequestParam @ApiIgnore Map<String, Object> query,
                                                         @RequestBody EditDeviceModel body) throws ServiceException {
        EditDeviceResponse responseBody = deviceService.editDevice(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /deleteDevice POST
    //region swagger响应码 : deleteDevice
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : deleteDevice
    @ApiOperation(value="删除设备", notes="删除设备  \n范围 : 系统  \n步骤 :  \n1. 在华为iot平台删除设备台账; (√)  \n",produces = "application/json")
    //endregion
    //region swagger参数 : deleteDevice
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : deleteDevice
    @RequestMapping(value = "/deleteDevice", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<DeleteDeviceResponse> deleteDevice(@RequestParam @ApiIgnore Map<String, Object> query,
                                                             @RequestBody DeleteDeviceModel body) throws ServiceException {
        DeleteDeviceResponse responseBody = deviceService.deleteDevice(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}












